﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class VipConfig extends Object
    {
        private var _vipDic:Dictionary;
        private static var _instance:VipConfig;

        public function VipConfig()
        {
            this._vipDic = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" VipConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_vip.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TVip = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TVip();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                this._vipDic[_loc_2.type] = _loc_2;
            }
            return;
        }// end function

        public function getVipConfigByType(param1:int) : TVip
        {
            return this._vipDic[param1];
        }// end function

        public function getVipLevelByMoney(param1:int) : int
        {
            var _loc_4:int = 0;
            var _loc_2:* = this.getVipConfigByType(EVipRecordType._EVipRecordTypeTotalGold);
            var _loc_3:int = 10;
            while (_loc_4 < 10)
            {
                
                if (param1 < _loc_2["vip" + (_loc_4 + 1)])
                {
                    _loc_3 = _loc_4;
                    break;
                }
                _loc_4++;
            }
            return _loc_3;
        }// end function

        public function getVipReChargeMoneyByLevel(param1:int) : int
        {
            var _loc_2:* = this.getVipConfigByType(EVipRecordType._EVipRecordTypeTotalGold);
            if (param1 == 10)
            {
                return int(_loc_2.vip10);
            }
            if (param1 == -1)
            {
                return int(_loc_2.vip1);
            }
            return int(_loc_2["vip" + (param1 + 1)]);
        }// end function

        public function getValueByTypeAndLv(param1:int, param2:int) : String
        {
            var _loc_5:String = null;
            var _loc_3:* = param1 > 100 ? (param1 / 10) : (param1);
            var _loc_4:* = this.getVipConfigByType(_loc_3);
            if (_loc_4)
            {
                if (param2 > 0)
                {
                    if (_loc_4.hasOwnProperty("vip" + param2))
                    {
                        _loc_5 = _loc_4["vip" + param2];
                    }
                }
                else if (param2 == -1)
                {
                    _loc_5 = _loc_4.vipExper;
                }
            }
            if (_loc_5)
            {
                return _loc_5;
            }
            return "0";
        }// end function

        public function isShowEffect(param1:int, param2:int) : Boolean
        {
            var _loc_3:* = this.getVipConfigByType(param1);
            return _loc_3 && _loc_3.hasOwnProperty("vip" + param2) && _loc_3["vip" + param2] == "1";
        }// end function

        public function get vipDic() : Dictionary
        {
            return this._vipDic;
        }// end function

        public static function get instance() : VipConfig
        {
            if (_instance == null)
            {
                _instance = new VipConfig;
            }
            return _instance;
        }// end function

    }
}
